import {createApp} from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
//全局引入Ant Design组件
//import Antd, {notification} from 'ant-design-vue';
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';
import * as Icons from '@ant-design/icons-vue'
import axios from 'axios';
import './assets/js/enums';

const app = createApp(App);
app.use(store).use(router).use(Antd).mount('#app')
//使用全局图标
const icons = Icons;
for (const i in icons) {
    app.component(i, icons[i])
}

/**
 * axios拦截器
 */
axios.interceptors.request.use(config => {
  /*  console.log('请求参数：', config);
    const token = store.state.member.token;
    if (token) {
        config.headers.token = token;
        console.log("请求headers增加token:", token);
    }*/
    return config;
}, error => {
    return Promise.reject(error);
});
axios.interceptors.response.use(response => {
    return response;
}, error => {
    console.log('返回错误：', error);
   /* const response = error.response;
    const status = response.status;
    if (status === 401) {
        // 判断状态码是401 跳转到登录页
        console.log("未登录或登录超时，跳到登录页");
        store.commit("setMember", {});
        notification.error({description: "未登录或登录超时"});
        router.push('/login').then(() => console.log("跳到登录页成功"));
    }
    notification.error({description: "未登录或登录超时"});*/
    return Promise.reject(error);
});

axios.defaults.baseURL = process.env.VUE_APP_SERVER;